/* $Header: wkfile.h,v 2.2 01/10/02 10:30:46 przybyls Exp $ */

/***********************************************************************/
/* INCLUDE FILE NAME:  wkfile.h                                        */
/* ==================                                                  */
/*                                                                     */
/* Author: Lesley Freed                                                */
/*                                                                     */
/* COMMENT:                                                            */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

#ifndef WKFILE_H
#define WKFILE_H

/*****************************/
/*   IFDEFS                  */
/*****************************/

/*-----begin change by wangwei-----------*/
#include "p_wkfile.h"
/*-----end change------------------------*/
/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/

#define MAX_STORED_WKFILE_SYZ 3000  /* max size for any stored workfile */
#define USR_STORED_WKFILE_MAX 2999  /* max size for any stored workfile */
#define MAX_STORED_WKFILE        9  /* max number of stored workfiles */
#define MAX_DETECTORS            2  /* max number of detectors */

/*****************************/
/*   TYPEDEFS                */
/*****************************/

typedef struct
{
        U_INT16         length;
        BIT8            crc[5];  /* hex formatted ASCII string: 4 chars + NULL */
        BIT8            name[21];
        BIT8            *data;
        DATETIME        dateTime;
} STORED_WKFILE;

/* REVISIT -- this should be from a memory pool */
typedef BIT8 STORED_WKFILE_DATA[MAX_STORED_WKFILE_SYZ];

/* Structures used by the signal path */

typedef struct
{
        BIT8      signal;      /* Signal Definition                          */
        BIT8      rate;        /* Signal Rate                                */

        U_INT32  *plot;        /* Pointer to Signal  Plot Data               */
        BIT8      size;        /* size of signal data                        */

                               /* NOTE:  bunch_count must be U_INT32 since   */
                               /*        it is used in a 64/32-bit divide    */
                               /*        so DO NOT CHANGE!!!!!!!!!!!!!!!!    */
        U_INT32 bunch_count;   /* # of data pts to bunch for sub 20Hz data   */

        INT32   zero;          /* Signal Zero                                */
        BIT8    DAC_rate;      /* DAC Data Rate                              */
        U_INT8  range;         /* Analog Signal Range                        */
        U_INT8  attn;          /* Analog Signal Attenuation                  */
        BIT8    zero_attn_on_off; /* Zero and Attn On/Off bits               */
                                  /*  Bit 0: 1 = Zero ON                     */
                                  /*  Bit 1: 1 = Attn ON                     */
} SIG_SETPTS, *pSIG_SETPTS;

/***** det flags structure *****/

typedef struct
{
        unsigned deta_polarity          :1;
        unsigned deta_flame             :1;
        unsigned deta_hiv               :1;   /* LDID plasma voltage */
        unsigned  /* unused */          :1;
        unsigned detb_polarity          :1;
        unsigned detb_flame             :1;
        unsigned detb_hiv               :1;
        unsigned  /* unused */          :1;
} DFLAGS;

typedef union
{
        DFLAGS  flag;
        U_INT8  byte;
} DET_FLAGS, *pDET_FLAGS;


typedef struct
{
        ON_OFF  cryo_on_off;           /* cryo On/Off Status                  */
        ON_OFF  cryo_blast_on_off;     /* cryo blast On/Off Status            */
        ON_OFF  cryo_timeout_on_off;   /* cryo timeout On/Off Status          */
        U_INT32 cryo_timeout_time;     /* cryo timeout                        */
        ON_OFF  cryo_shutdown_on_off;  /* cryo shutdown On/Off Status         */
        U_INT32 cryo_ambient_temp;     /* cryo ambient temperature in         */
                                       /*  internal temperature units         */
} CRYO_SETPTS, *pCRYO_SETPTS;

/***** CPF det control structure *****/

typedef struct
{
        U_INT16 on_off;  /* on/off of control bits for CPF's OI board */
        U_INT16 value;  /* value of control bits for CPF's OI board */
} DET_CPF_CTL;

/******************************************/
/******************************************/
/**    Workfile Structure                **/
/******************************************/
/******************************************/

typedef struct
{
        BIT8      name[21];

/* Detector Setpoints */

        BIT8 detectors_on_off;  /* on/off setpoints in DISCRETE_OUT1 */
        DET_FLAGS det_flags;    /* detector-specific setpoints */
        U_INT16 det_target_offset[MAX_DETECTORS];
        U_INT32 det_equib_time[MAX_DETECTORS];
        U_INT16 det_lit_offset[MAX_DETECTORS];
        DET_CPF_CTL det_cpf_ctl[MAX_DETECTORS];  /* control bits for CPF's OI board */

/* Signal Setpoints */

        SIG_SETPTS signal1;       /* setpoints for signal 1                   */
        SIG_SETPTS signal2;       /* setpoints for signal 2                   */
        SIG_SETPTS signalP;       /* setpoints for signal P                   */
        POSITION   col_comp1_det; /* det position for getting scc 1 profile  */
        POSITION   col_comp2_det; /* det position for getting scc 2 profile  */

/* Valve Setpoints */

        U_INT8     stream_no;       /* Multiposition valve setpoint */
        ON_OFF     valve[8];        /* Valve setpoint               */
        U_INT32    load_time[8];    /* GSV load time                */
        U_INT32    inject_time[8];  /* GSV injection time           */

/* Zone Setpoints */

        BIT8    zones_on_off;          /* zones On/Off Status                 */
        BIT8    zones_oven_track_mode; /* zones in oven track setpt mode      */
        U_INT32 equib_time;            /* time in units of cmin, (.01 min)    */

        CRYO_SETPTS  oven_cryo;
        CRYO_SETPTS  inja_cryo;
        CRYO_SETPTS  injb_cryo;
        CRYO_SETPTS  auxa_cryo;
        CRYO_SETPTS  auxb_cryo;

/* Pneumatic Setpoints */

       PNEU_WKFILE Pneu;

/* Post Time setpoint (NOTE: Post value setpoint is in RAMPTBL */
/* structure, but there is only one post time.                 */

          INT32  post_time;

/* Ramp Setpoints - Thermal Zones */

        RAMPTBL  oven_temp;
        RAMPS    oven_ramps[ OVEN_RAMP_LEVELS ];

        RAMPTBL      inja_temp;
        RAMPS        inja_ramps[ RAMP_LEVELS ];

        RAMPTBL      injb_temp;
        RAMPS        injb_ramps[ RAMP_LEVELS ];

        RAMPTBL      deta_temp;
        RAMPS        deta_ramps[ DET_RAMP_LEVELS ];

        RAMPTBL      detb_temp;
        RAMPS        detb_ramps[ DET_RAMP_LEVELS ];

        RAMPTBL      auxa_temp;
        RAMPS        auxa_ramps[ RAMP_LEVELS ];

        RAMPTBL      auxb_temp;
        RAMPS        auxb_ramps[ RAMP_LEVELS ];

/* Run Table Entries  */

        TIME_TABLE Run_Time_Table;

/* Sampler Setpoints */
/* In Vireo the sampler setpoints are stored in their own power-fail */
/* protected structure.  See sampler.h for definition.               */

} WKFILE;

#define npd_bead_voltage det_lit_offset

/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/

#pragma SECTION DATA=pfail

extern  WKFILE  Active_Wkfile;
extern  STORED_WKFILE Stored_Wkfile[];
extern  STORED_WKFILE_DATA  Stored_Wkfile_Data[];

#pragma SECTION UNDO
#endif
